<%#
kind: snippet
name: ansible_tower_callback_script
model: ProvisioningTemplate
snippet: true
description: |
  The script that calls to the Ansible Tower / AWX to trigger a job on the host. Typically used
  during provisioning to trigger one Ansible run on newly provisioned host.
-%>
#!/bin/sh

echo "Calling Ansible AWX/Tower provisioning callback..."
<% if host_param('ansible_extra_vars') -%>
/usr/bin/curl -v -k -s -H 'Content-Type: application/json' --data '{"host_config_key":"<%= host_param('ansible_host_config_key') %>", "extra_vars": <%=host_param('ansible_extra_vars') %>}' <%= host_param('ansible_tower_api_url') %>/job_templates/<%= host_param('ansible_job_template_id') %>/callback/
<% else -%>
/usr/bin/curl -v -k -s --data "host_config_key=<%= host_param('ansible_host_config_key') %>" <%= host_param('ansible_tower_api_url') %>/job_templates/<%= host_param('ansible_job_template_id') %>/callback/
<% end -%>
echo "DONE"
